package cn.eyesea.cc.frame.base.impl.resultresource;

import cn.eyesea.cc.config.GlobalConfig;
import cn.eyesea.cc.frame.base.ResourceFunction;
import cn.eyesea.cc.frame.base.ResultResource;
import cn.eyesea.cc.frame.enums.ResultTypeEnum;
import cn.eyesea.cc.util.ConfigUtil;
import cn.eyesea.cc.util.VelocityUtils;
import lombok.Data;

import java.util.Map;

/**
 * 变量结果资源
 *
 * @author wanghuilong
 * @version 1.0
 * @date 2021/7/26 5:49 下午
 */
@Data
public class VariableResultResource extends ResultResource {

    /**
     * 变量类型
     */
    ResultResource variableType;

    /**
     * 注释
     */
    String comment;

    @Override
    public ResultTypeEnum getResourceType() {
        return ResultTypeEnum.JAVA_VARIABLE;
    }

    @Override
    public void usage(ResourceFunction resourceFunction) {
        //java 类引用,导包

    }

    @Override
    public void usage(ResultResource resultResource) {
        //java 类引用,导包
    }

    @Override
    public void generateCode(GlobalConfig globalConfig) {
        if (getNeedGenerateCode()) {
            Map<String, Object> param = ConfigUtil.getDefaultParam(globalConfig);
            param.put("linesCommont", getComment());
            param.put("variableType", getVariableType().getName());
            param.put("variableName", getName());
            setGenerateCode(VelocityUtils.generate("/template/variable.vm", param));
        }
    }

}
